package com.kmproject.haifu.mvp.ui.holder;

import android.content.Context;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import com.jess.arms.utils.ArmsUtils;
import com.kmproject.haifu.R;
import com.kmproject.haifu.app.utils.StringUtils;
import com.kmproject.haifu.mvp.model.entity.beans.HousePayWayBean;
import com.kmproject.haifu.mvp.ui.adapter.SecondHandPublicshBqAdapter;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

public class SxSecondHandHolder {
    @BindView(R.id.secondhand_seelct_RecyclerView)
    RecyclerView secondhandSeelctRecyclerView;
    @BindView(R.id.secondhand_seelct_zj_zdj)
    EditText secondhandSeelctZjZdj;
    @BindView(R.id.secondhand_seelct_zj_zgj)
    EditText secondhandSeelctZjZgj;
    @BindView(R.id.secondhand_seelct_sx_clearTv)
    TextView secondhandSeelctSxClearTv;
    @BindView(R.id.secondhand_seelct_sx_sureTv)
    TextView secondhandSeelctSxSureTv;
    SecondHandPublicshBqAdapter secondHandPublicshBqAdapter;
    Context mcontext;
    public SxSecondHandHolder(Context context, View view) {
//        R.layout.secondhand_seelct_sx
        mcontext=context;
        ButterKnife.bind(this, view);
    }

    public void init(List<HousePayWayBean> housePayWayBeans,SxSelectCallback sxSelectCallback){
        secondhandSeelctRecyclerView.setLayoutManager(new GridLayoutManager(mcontext,3));
        secondHandPublicshBqAdapter = new SecondHandPublicshBqAdapter(housePayWayBeans);
        secondhandSeelctRecyclerView.setAdapter(secondHandPublicshBqAdapter);
        secondhandSeelctSxClearTv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                sxSelectCallback.callback(null,null,null);
            }
        });
        secondhandSeelctSxSureTv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (StringUtils.ViewisEnpty(secondhandSeelctZjZdj)&&StringUtils.ViewisEnpty(secondhandSeelctZjZgj))
                {
                    //最低和最高价格都是空的
                    sxSelectCallback.callback(null,null,getLabs(secondHandPublicshBqAdapter.getData()));
                    return;
                }
                if (StringUtils.ViewisEnpty(secondhandSeelctZjZdj))
                {
                    ArmsUtils.makeText(mcontext,"请输入最低价格");
                    return;
                }
                if (StringUtils.ViewisEnpty(secondhandSeelctZjZgj))
                {
                    ArmsUtils.makeText(mcontext,"请输入最高价格");
                    return;
                }
                sxSelectCallback.callback(secondhandSeelctZjZdj.getText().toString(),secondhandSeelctZjZgj.getText().toString(),getLabs(secondHandPublicshBqAdapter.getData()));

            }
        });
    }
    /**
     * 得到选中的标签id
     *
     * @param housePayWayBeansBq
     * @return
     */
    public List<String> getLabs(List<HousePayWayBean> housePayWayBeansBq) {
        List<String> labsIds = null;
        if (housePayWayBeansBq == null || housePayWayBeansBq.isEmpty()) {
            return labsIds;
        }
        for (HousePayWayBean housePayWayBean : housePayWayBeansBq) {
            if (housePayWayBean.isSelect()) {
                if (labsIds==null)
                {
                    labsIds =new ArrayList<>();
                }
                labsIds.add(housePayWayBean.getDictId());
            }
        }
        return labsIds;
    }
    public interface SxSelectCallback{
//        private String beginSalePrice;
//        private String endSalePrice;
        public void callback(String beginSalePrice, String endSalePrice, List<String> labids);
    }
}
